package com.wy.component.ehcache;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class EhcacheUtil {
	
	static CacheManager cacheManager = CacheManager.getInstance();
	static Cache cacheConfig = cacheManager.getCache("CacheConfig");
	static Cache cacheSql = cacheManager.getCache("CacheSql");
	
	/**
	 * Function Name               getEhcacheValue                                   
	 * @param key
	 * @return          		             
	 * @description 根据key得到ehcache的config值
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-5-19 上午10:35:01           张旭星                     Initial
	 **********************************************************************
	 */
	public static String getEhcacheConfigValue(String key) {
		synchronized (cacheConfig) {
			return (String) cacheConfig.get(key).getValue();
		}
	}
	
	public static void setEhcacheConfigValue(String key,String value) {
		Element element = new net.sf.ehcache.Element(
				key, value);
		cacheConfig.put(element);
	}
	
	/**
	 * Function Name               getEhcacheSqlValue                                   
	 * @param key
	 * @return          		             
	 * @description 根据key得到ehcache的sql值
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-5-28 上午11:40:04           张旭星                     Initial
	 **********************************************************************
	 */
	public static String getEhcacheSqlValue(String key) {
		synchronized (cacheSql) {
			return (String) cacheSql.get(key).getValue();
		}
	}
	
	public static void setEhcacheSqlValue(String key,String value) {
		Element element = new net.sf.ehcache.Element(
				key, value);
		cacheSql.put(element);
	}
	
}
